Imports System.Data.SqlClient
Imports CommunityServer.Membership
Imports CommunityServer.WebServices.Membership
Imports NENAData.NENAMember

Public Class ViewAllCommittee

    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents dlstCommittee As System.Web.UI.WebControls.DataList

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim oApiUser As APIUser = New APIUser()
        Dim oRoles As List(Of Role) = Session("Roles")

        If Not oApiUser.IsMemberInRole(oRoles, "MembershipAdministrator") Then
            Response.Redirect("")
        End If
        If Not IsPostBack Then
            BindDataList()
        End If

    End Sub


    Sub BindDataList()

        Dim conPubs As SqlConnection
        Dim cmdSelect As SqlCommand
        Dim dtrTitles As SqlDataReader
        Dim strSql As String

        strSql = "select * from Members_Committee where " & _
       "Active_Status = '" & ConfigurationManager.AppSettings.Item("Active_Status_Active") & "' " & _
       "order by LastName"

        conPubs = New SqlConnection(ConfigurationManager.AppSettings.Item("SQLConnectionString"))
        cmdSelect = New SqlCommand(strSql, conPubs)
        conPubs.Open()
        dtrTitles = cmdSelect.ExecuteReader()

        dlstCommittee.DataSource = dtrTitles
        dlstCommittee.DataBind()

        dtrTitles.Close()
        conPubs.Close()
    End Sub

    Sub dlstCommittee_UpdateCommand(ByVal s As Object, ByVal e As DataListCommandEventArgs)
        Dim conPubs As SqlConnection
        Dim strUpdate As String
        Dim cmdUpdate As SqlCommand

        Dim txtEditFirstName As TextBox
        Dim txtEditLastName As TextBox
        Dim txtEditNameID As TextBox
        Dim txtEditphonehome As TextBox
        Dim txtEditphonework As TextBox
        Dim txtEditfaxhome As TextBox
        Dim txtEditfaxwork As TextBox
        Dim txtEditemail As TextBox
        Dim txtEditaddress1 As TextBox
        Dim txtEditaddress2 As TextBox
        Dim txtEditcity As TextBox
        Dim txtEditprovince As TextBox
        Dim txtEditpostalcode As TextBox

        Dim strEditFirstName, strEditLastName, strEditFullName As String
        Dim strEditNameID As String
        Dim strEditphonehome As String
        Dim strEditphonework As String
        Dim strEditfaxhome As String
        Dim strEditfaxwork As String
        Dim strEditemail As String
        Dim strEditaddress1 As String
        Dim strEditaddress2 As String
        Dim strEditcity As String
        Dim strEditprovince As String
        Dim strEditpostalcode As String

        txtEditFirstName = e.Item.FindControl("EditFirstName")
        txtEditLastName = e.Item.FindControl("EditLastName")
        txtEditNameID = e.Item.FindControl("EditNameID")
        txtEditphonehome = e.Item.FindControl("EditPhonehome")
        txtEditphonework = e.Item.FindControl("EditPhonework")
        txtEditfaxhome = e.Item.FindControl("EditFaxhome")
        txtEditfaxwork = e.Item.FindControl("EditFaxwork")
        txtEditemail = e.Item.FindControl("editemail")
        txtEditaddress1 = e.Item.FindControl("EditAddress1")
        txtEditaddress2 = e.Item.FindControl("EditAddress2")
        txtEditcity = e.Item.FindControl("EditCity")
        txtEditprovince = e.Item.FindControl("Editprovince")
        txtEditpostalcode = e.Item.FindControl("EditPostalCode")

        strEditFirstName = txtEditFirstName.Text
        strEditLastName = txtEditLastName.Text
        strEditFullName = strEditFirstName & " " & strEditLastName
        strEditNameID = txtEditNameID.Text
        strEditphonehome = txtEditphonehome.Text
        strEditphonework = txtEditphonework.Text
        strEditfaxhome = txtEditfaxhome.Text
        strEditfaxwork = txtEditfaxwork.Text
        strEditemail = txtEditemail.Text
        strEditaddress1 = txtEditaddress1.Text
        strEditaddress2 = txtEditaddress2.Text
        strEditcity = txtEditcity.Text
        strEditprovince = txtEditprovince.Text
        strEditpostalcode = txtEditpostalcode.Text

        conPubs = New SqlConnection(ConfigurationManager.AppSettings.Item("SQLConnectionString"))
        strUpdate = "Update Members_Committee set FirstName='" & strEditFirstName & _
         "',LastName='" & strEditLastName & _
         "',FullName='" & strEditFullName & _
         "',Phone_home='" & strEditphonehome & _
         "',Phone_work='" & strEditphonework & _
         "',Fax_Home='" & strEditfaxhome & _
         "',Fax_work='" & strEditfaxwork & _
         "',Email='" & strEditemail & _
         "',Address_1='" & strEditaddress1 & _
         "',Address_2='" & strEditaddress2 & _
         "',City='" & strEditcity & _
         "',Province='" & strEditprovince & _
         "',Postal_Code='" & strEditpostalcode & _
         "' Where Id='" & strEditNameID & "';"


        cmdUpdate = New SqlCommand(strUpdate, conPubs)
        conPubs.Open()
        cmdUpdate.ExecuteNonQuery()
        conPubs.Close()

        dlstCommittee.EditItemIndex = -1
        BindDataList()

    End Sub

    Sub dlstCommittee_EditCommand(ByVal s As Object, ByVal e As DataListCommandEventArgs)
        dlstCommittee.EditItemIndex = e.Item.ItemIndex
        BindDataList()
    End Sub

    Sub dlstCommittee_CancelCommand(ByVal s As Object, ByVal e As DataListCommandEventArgs)
        dlstCommittee.EditItemIndex = -1
        BindDataList()

    End Sub


End Class
